class Solution86 {
    public ListNode partition(ListNode head, int x) {
        head = new ListNode(0, head);
        ListNode p = head.next;
        ListNode small = head, big = new ListNode(), bp = big;
        while (p != null) {
            if (p.val < x) {
                small.next = p;
                small = small.next;
            } else {
                bp.next = p;
                bp = bp.next;
            }
            p = p.next;
        }
        bp.next = null;
        small.next = big.next;
        return head.next;
    }
}
